package com.frxuexi.repair

import com.frxuexi.lib_base.http.ApiService
import com.frxuexi.lib_base.mvi.BaseViewModel
import com.frxuexi.lib_base.mvi.RequestType
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class RepairViewModel @Inject constructor(val apiService: ApiService):BaseViewModel<RepairIntent>(){
    override fun handlerIntent(it: RepairIntent) {
        when(it){
            is RepairIntent.getRepairs->{
                httpRequest(apiService.getRepairs())
            }
            is RepairIntent.getRepairByNum->{
                httpRequest(apiService.getRepairByNum(it.num),RequestType.REPIRITM)
            }
            is RepairIntent.getRepairByUser->{
                httpRequest(apiService.getRepairByUser((it.user)))
            }
            is RepairIntent.addRepair->{
                httpRequest(apiService.addRepair(toBody(it.bean)))

            }
            is RepairIntent.deleteRepair->{
                httpRequest(apiService.deleteRepair(it.id),RequestType.DELETE)
            }
            is RepairIntent.getRepairById->{
                httpRequest(apiService.getRepairById(it.id))
            }
            is RepairIntent.updateRepair->{
                httpRequest(apiService.updateRepair(it.id,toBody(it.bean)),RequestType.UPDATE)
            }

            else->{}
        }
    }
}